package com.base.vistter.iframe.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.base.vistter.iframe.entity.InverterDevicesPowerDay;
import com.base.vistter.iframe.entity.InverterDevicesPowerMonth;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

@Mapper
public interface InverterDevicesPowerMonthMapper extends BaseMapper<InverterDevicesPowerMonth> {

    @Select("SELECT ${column},report_time FROM inverter_devices_power_month WHERE inverter_devices_id = #{devicesId} and is_delete = 0 and report_time BETWEEN #{startTime} AND #{endTime} order by report_time ASC")
    List<InverterDevicesPowerMonth> statisticsDevicesMonth(@Param("column") String column, @Param("devicesId") Integer devicesId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);

    @Select("SELECT ${column},report_time FROM inverter_devices_power_day WHERE inverter_devices_id = #{devicesId} and is_delete = 0 and report_time BETWEEN #{startTime} AND #{endTime} order by report_time ASC LIMIT 1")
    InverterDevicesPowerMonth getTodayPower(@Param("column") String column, @Param("devicesId") Integer devicesId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);

    @Select({
            "<script>",
                "SELECT sum(dp) as dp,report_time FROM inverter_devices_power_month ",
                "WHERE is_delete = 0 ",
                " <if test='stationId != null'> AND inverter_station_id = #{stationId} </if>",
                " and report_time BETWEEN #{startTime} AND #{endTime}",
                " group by report_time order by report_time ASC",
            "</script>"})
    List<InverterDevicesPowerMonth> statisticsMonth(@Param("stationId") Integer stationId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);

}
